<template>
  <div class="main">
    <div style="width:7.5rem;" class="selectNews1Wrap">
      <div class="top flex-h">
        <span @click="goBackApp" style="width: 3rem;display: inline-block;"><i class="imgIcon"></i> </span>
        <span class="flex1 univTitle"></span>
      </div>
      <scroller style="top: 0.8rem;">
        <div>
          <div>
            <div class="rmwdBox">
              <div class="dtBox">
                <span class="dtSp">热门问答</span>
              </div>
              <!-- <div>{{answerId}}</div> -->
              <div class="wentibox">
                <div class="wdAvatar flex-h">
                  <img :src="infoData.avatar ? infoData.avatar : usersImg" alt="" />
                  <span class="flex1 wdsp">
                    <b>{{ infoData.name }}</b>
                    <i>{{ authorData.createTime }}</i></span
                  >
                </div>
                <div class="wdTil">
                  <span>{{ authorData.title }}</span>
                </div>
                <div class="wdNum">{{ authorData.answer_count }}条回答</div>
              </div>
              <div class="wdDetail">
                <div class="wdDeBox" v-for="(ites, index) in answerData" :key="index">
                  <div class="deTop">
                    <img :src="ites.user_avatar ? ites.user_avatar : usersImg" alt="" />
                    <span class="deSpan">
                      <b>{{ ites.user_name ? ites.user_name : '--' }}</b>
                      <i>{{ ites.create_time }}</i>
                    </span>
                  </div>
                  <span class="quesDe">{{ ites.text }}</span>
                </div>
              </div>
            </div>
          </div>
          <div style="width: 100%;height: 20vh;"></div>
        </div>
      </scroller>
    </div>
  </div>
</template>
<script>
import {} from 'vux'
import goBack from '~/components/goBack'
import { answerServiceQuestions, answerService } from '~/api/school'
import ls from 'store2'
import { format } from '~/plugins/filter'
export default {
  data() {
    return {
      usersImg: require('~/static/usermoren.png'),
      authorData: {},
      answerData: [],
      infoData: [],
    }
  },
  created() {
    if (this.commonJs.checkTerminal() === 'ios') {
      let iOSInfos = window.iOSInfo
      this.answerId = iOSInfos.answerId
    } else if (this.commonJs.checkTerminal() === 'android') {
      this.answerId = this.commonJs.GetMallParam('answerId')
    } else {
      // this.answerId = this.commonJs.GetMallParam("answerId")
      this.answerId = this.$route.query.type
    }
  },
  mounted: function() {
    this.showTitleDeatil()
  },
  destroyed() {},
  watch: {},
  methods: {
    goBackApp() {
      if (this.commonJs.checkTerminal() === 'ios') {
        window.webkit.messageHandlers.backMessage.postMessage('back')
      } else if (this.commonJs.checkTerminal() === 'android') {
        ZMParentsJsToAndroid.backMessage('back')
      } else {
        window.history.go(-1)
      }
    },

    showAnswers() {
      answerServiceQuestions(this.answerId)
        .then((res) => {
          this.answerData = res.data
          this.$hideLoading()
        })
        .catch((error) => {
          this.$vux.toast.text('暂无数据')
          this.$hideLoading()
        })
    },
    showTitleDeatil() {
      this.$loading('open')
      answerService(this.answerId)
        .then((res) => {
          this.authorData = res
          this.infoData = res.author

          this.showAnswers()
        })
        .catch((error) => {
          this.$hideLoading()
        })
    },
  },
}
</script>

<style lang="less">
.selectNews1Wrap {
  width: 7.5rem;
  min-height: 100vh;
  background: #fff;
  padding: 0 0.3rem;
  box-sizing: border-box;

  .top {
    width: 100%;
    height: 0.8rem;
    line-height: 0.8rem;

    .imgIcon {
      display: inline-block;
      width: 0.4rem;
      height: 0.4rem;
      background: url('~@/static/sprite/icon_sprites_40.png') -0.1rem -0.1rem;
      background-size: 3rem 2.4rem;
    }

    .univTitle {
      text-align: center;
      font-size: 0.4rem;
      font-weight: bold;
      color: rgba(34, 34, 34, 1);
    }
  }

  .dtBox {
    width: 100%;
    padding: 0 0.3rem;
    box-sizing: border-box;
    height: auto;
    padding-bottom: 0.3rem;
    padding-top: 0.2rem;
    // border-bottom: 1px solid rgba(238, 238, 238, 1);
    font-size: 0.3rem;

    span {
      font-size: 0.44rem;

      font-weight: bold;
      color: rgba(34, 34, 34, 1);
      line-height: 0.4rem;
    }

    b {
      display: block;

      font-size: 0.26rem;

      font-weight: 500;
      color: rgba(187, 187, 187, 1);
      text-align: right;
      margin-top: 0.15rem;
    }
  }
}

.wentibox {
  border-bottom: 0.2rem solid rgba(250, 250, 250, 1);

  .wdAvatar {
    width: 100%;
    height: 1.4rem;
    padding: 0.3rem;
    box-sizing: border-box;

    img {
      width: 0.8rem;
      height: 0.8rem;
      border-radius: 50%;
      display: block;
    }

    .wdsp {
      padding-left: 0.2rem;
      box-sizing: border-box;

      b,
      i {
        display: block;
      }

      b {
        font-size: 0.26rem;
        line-height: 0.41rem;
        font-weight: bold;
        color: rgba(34, 34, 34, 1);
      }

      i {
        font-size: 0.24rem;

        font-weight: 500;
        color: rgba(187, 187, 187, 1);
        line-height: 0.4rem;
      }
    }
  }

  .wdTil,
  .wdNum {
    width: 100%;
    height: auto;
    padding: 0 0.3rem;
    box-sizing: border-box;
  }

  .wdTil {
    font-size: 0.3rem;

    span {
      font-size: 0.3rem;
      font-weight: bold;
      font-weight: 600;
      color: rgba(34, 34, 34, 1);
      line-height: 0.45rem;
    }
  }

  .wdNum {
    font-size: 0.26rem;
    height: 0.8rem;
    font-weight: 500;
    color: rgba(153, 153, 153, 1);
    line-height: 0.8rem;
    text-align: right;
  }
}

.wdDetail {
  width: 100%;
  height: auto;
  padding: 0 0.3rem;
  margin-top: 0.05rem;
  box-sizing: border-box;
  overflow: hidden;

  .wdDeBox {
    width: 100%;
    // height: 1.95rem;
    // background: rgba(250, 250, 250, 1);
    border-radius: 0.04rem;
    padding: 0.4rem 0.2rem;
    box-sizing: border-box;
    font-size: 0.3rem;
    border-bottom: 1px solid rgba(238, 238, 238, 1);

    .deTop {
      height: 0.8rem;
      font-size: 0.3rem;
      line-height: 0.8rem;
      margin-bottom: 0.07rem;

      img {
        width: 0.8rem;
        height: 0.8rem;
        border-radius: 50%;
        display: inline-block;
        vertical-align: middle;
      }

      .deSpan {
        display: inline-block;
        height: 0.8rem;
        vertical-align: middle;
        padding-left: 0.2rem;
        box-sizing: border-box;

        i,
        b {
          display: block;
          font-size: 0.26rem;
          line-height: 0.4rem;
        }

        b {
          font-weight: bold;
          color: rgba(34, 34, 34, 1);
        }

        i {
          color: rgba(187, 187, 187, 1);
        }
      }
    }

    .quesDe {
      font-size: 0.26rem;
      margin-top: 0.15rem;
      margin-left: 1rem;
      font-weight: 500;
      color: rgba(102, 102, 102, 1);
      line-height: 0.4rem;
    }
  }
}
</style>
